package LeetCode.LeetCode2;

/**
 * 买卖股票的最佳时机
 * @author lumin
 * @date 2022/03/23 11:45
 **/
public class Num121 {
    public int maxProfit(int[] prices) {
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < prices.length; i++) {
            if(prices[i] <= min){
                min = prices[i];
            }
            if(prices[i] - min > max){
                max = prices[i] - min;
            }
        }
        return max;
    }
}